const app = getApp();
Page({
  data: {
    card_id:'',
    card_info:[],
    type_list:['存款','欠款'],
    index:0,
  },

  onShow:function(){
    
  },

  onLoad:function(options){
    let _this = this;
      _this.setData({
        card_id:options.card_id
      })
      _this.getUserInfo(); //获取用户信息
  },

  
  //获取个人信息
  getUserInfo:function(){
    let _this = this;
    app._post('api/member/getUserInfo', {}, function(result) {
      if(result.code == 200){
        _this.get_card_info();
      }else{
        wx.navigateTo({
          url: '/pages/auth/auth'
        })
      }
    });
  },

  //获取银行卡列表
  get_card_info:function(){
    let _this = this;
    app._post('api/member/get_card_info', {card_id:_this.data.card_id}, function(result) {
      _this.setData({
        card_info:result.data
      })
    });
  },

  //资产类型选择
  TypeChange:function(e){
    let _this = this,
     index = e.detail.value;
    _this.setData({
      index:index
    })
  },

  //提交表单
  formSubmit:function(e){
    console.log(e);
    let _this = this,
      form_data = e.detail.value,
      money = form_data.money,
      type_list = _this.data.type_list;
    if(money == ''){
      wx.showToast({
        title: '金额不能为空',
        icon: 'none',
        duration: 2000
      })
    }else{
      app._post('api/member/sub_card', {
        card_id:_this.data.card_id,
        money:money,
        card_num:form_data.card_num,
        beizhu:form_data.beizhu,
        money_type:type_list[_this.data.index],
      }, function(result) {
        
      });
    }
  }
})